//
//  YHLabel.swift
//  YHKit
//
//  Created by amovision on 2025/9/4.
//

import UIKit

open class YHLabel: UILabel {
  public let background = UIView()
  // 自定义的内边距属性
  open var textInset = UIEdgeInsets.zero {
    didSet {
      layoutIfNeeded()
    }
  }
  
  open override var isHidden: Bool {
    set {
      super.isHidden = newValue
      background.isHidden = newValue
    }
    get {
      return super.isHidden
    }
  }
  
  open override func layoutSubviews() {
    super.layoutSubviews()
    if let superview {
      if background.superview == nil {
        superview.insertSubview(background, belowSubview: self)
      }
      background.remakeConstraints { make in
        make.edges.equalTo(self).inset(UIEdgeInsets(-textInset.top, -textInset.left, -textInset.bottom, -textInset.right))
      }
    }
  }
}
